// src/api/levelAdjustment-api.js
import axios from 'axios';

// 创建 axios 实例
const api = axios.create({
  baseURL: 'http://localhost:8082', // 根据实际后端服务修改
  timeout: 8000
});

// 获取可调级员工列表
export function getAdjustableEmployees(departmentId, userId, userRole) {
  return api.get('/api/level-adjustment/employees', {
    params: {
      departmentId: departmentId  // 设置查询参数，传递部门 ID
    },
    headers: {
      'X-User-Id': userId,   // 传递当前用户 ID
      'X-User-Role': userRole  // 传递当前用户角色
    }
  })
  .then(response => {
    // 请求成功后返回员工数据
    return response.data;
  })
  .catch(error => {
    // 请求失败时的错误处理
    console.error('获取员工列表失败:', error);
    throw error;
  });
}

// 调整员工级别
export function adjustLevel(data, operatorId, operatorRole) {
  return api.post('/api/level-adjustment/adjust', data, {
    headers: {
      'Content-Type': 'application/json',
      'X-User-Id': operatorId,
      'X-User-Role': operatorRole
    },
    withCredentials: true
  });
}

// 获取调级记录
export function getAdjustmentRecords(params = {}) {
  return api.get('/api/level-adjustment/records', { params });
}

// 获取所有员工（下拉筛选用）
export function getAllEmployees() {
  return api.get('/api/level-adjustment/all-employees');
}

// 获取薪资级别列表（修复 request() 为 api.get）
export function getSalaryLevels() {
  return api.get('/api/salary/levels');
}
